#!/usr/bin/env python3
# -*- coding: UTF-8 -*-

"""
@author: JoeyZhou
@Tool: PyCharm
@Date: 2020/1/7 8:49 PM
"""

import requests
import json
# from BeautifulReport import BeautifulReport


class DingTalk:
    def __init__(self):
        self.headers = {'Content-Type': 'application/json'}
        # WebHook测试组
        self.url = "https://oapi.dingtalk.com/robot/send?access_token=cd40d95ee38090e9fd841c0a1312ddc0e4253159a756834969eadbc9e4efaafd"

        # 正宗卖家测试小组（供应侧业务测试组）
        # self.url = "https://oapi.dingtalk.com/robot/send?access_token=6aea52334ab72709678ea352d11e67b0c371f8e3e24792500b80c26943fe45bb"

    def send_msg(self, text):
        json_text = {
            "msgtype": "text",
            "text": {
                "content": text,
            },
            "at": {
                "atMobiles": [
                    ""
                ],
                "isAtAll": False
            }
        }
        return requests.post(self.url, json.dumps(json_text), headers=self.headers).content


if __name__ == '__main__':
    ding = DingTalk()
    # ding.send_msg("JARVIS系统已启动")
    a = "本次接口自动化执行结果如下：\n开始时间：%s\n运行时间：%s\n用例总数：%d\n用例通过：%d\n用例失败：%d\n用例跳过：%d\n报告页面：" \
        % ("2020-01-22 17:38:55", "24s", 5, 3, 1, 1)
    ding.send_msg(a)


